﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CSEPT.Controllers
{
    public class EventController : Controller
    {
        //
        // GET: /Event/
        [LoggedIn]
        public ActionResult Index()
        {
            return RedirectToAction("Index", "Index");
        }
        [LoggedIn]
        public ActionResult Create()
        {
            Models.EventViewModel EVM = new Models.EventViewModel();
            return View(EVM);
        }
        [LoggedIn]
        public ActionResult Update(Event EventToModify)
        {
            Models.EventViewModel EVM = new Models.EventViewModel();
            if (EventToModify.Owner.ID != EVM.CurrUser.ID && EventToModify.Owner.ID != 0)
            {
                return RedirectToAction("IndexInfo", "Index", new { @Message = "You cannot change an event you didn't creat.", @Type = "warning" });
            }
            EVM.dal.UpdateEvent(EventToModify);
            return RedirectToAction("IndexInfo", "Index", new { @Message = "Event Succesfully Created", @Type = "success" });
        }
        [LoggedIn]
        public ActionResult Modify(int EventID)
        {
            Models.EventViewModel EVM = new Models.EventViewModel();
            EVM.EventToModify = EVM.dal.GetEvent(EventID);
            if (EVM.EventToModify.Owner.ID != EVM.CurrUser.ID)
            {
                return RedirectToAction("IndexInfo", "Index", new {@Message = "You cannot change an event you didn't creat.", @Type = "warning"});
            }
            return View("Create", EVM);
        }
        [LoggedIn]
        public ActionResult Remove(int EventID)
        {
            Models.EventViewModel EVM = new Models.EventViewModel();
            EVM.EventToModify = EVM.dal.GetEvent(EventID);
            if (EVM.EventToModify.Owner.ID != EVM.CurrUser.ID)
            {
                return RedirectToAction("IndexInfo", "Index", new { @Message = "You cannot change an event you didn't creat.", @Type = "warning" });
            }
            return View(EVM);
        }
        [LoggedIn]
        public ActionResult Delete(int EventID)
        {
            Models.EventViewModel EVM = new Models.EventViewModel();
            EVM.EventToModify = EVM.dal.GetEvent(EventID);
            if (EVM.EventToModify.Owner.ID != EVM.CurrUser.ID)
            {
                return RedirectToAction("IndexInfo", "Index", new { @Message = "You cannot change an event you didn't creat.", @Type = "warning" });
            }
            EVM.dal.DeleteEvent(EVM.EventToModify);
            return RedirectToAction("IndexInfo", "Index", new { @Message = "Event Succesfully removed", @Type = "warning" });
        }
    }
}
